// var $macros = require("./AL_Framework_Macros");
// var n = (function () {
//     function e() {
//         this.logTag = "[AL_Framework_SDK_Helper]";
//         this.videoState = !1;
//     }
//     e.Instance = function () {
//         return this._instance || (this._instance = new e());
//     };
//     e.prototype.vibrate = function (e) {
//         if (void 0 === e) {
//             e = !1;
//         }
//         if (Manager.settingStorage.zhendong_zhuangtai) {
//             e ? ailin_sdk_manager.vibrateLong() : ailin_sdk_manager.vibrateShort();
//         }
//     };
//     e.prototype.handle_fenxiang_huo_shipin_huidiao = function (e) {
//         var t = this;
//         if (void 0 === e) {
//             e = {};
//         }
//         var o = this.huoquFenxiangHuoShipinZhuangtai();
//         0 === o
//             ? e.notExistCall
//                 ? e.notExistCall()
//                 : Manager.tips.show(Manager.languageManager.huoqu_biaoqian_neirong("framework", "暂无视频"))
//             : 2 == o &&
//               ((this.videoState = !0),
//               (window.vivoPlayVDCallBack = function () {
//                   setTimeout(function () {
//                       Manager.eventCenter.emit($macros.Macro.CHANGE_MUSIC_EVENT, !0);
//                   }, 100);
//                   t.videoState = !1;
//               }),
//               ailin_sdk_manager.xianshiJiliShipinGuanggao(function (t) {
//                   t
//                       ? e.success && e.success()
//                       : e.fail
//                       ? e.fail()
//                       : Manager.tips.show(Manager.languageManager.huoqu_biaoqian_neirong("framework", "视频播放失败"));
//               }));
//     };
//     e.prototype.huoquFenxiangHuoShipinZhuangtai = function () {
//         return ailin_sdk_manager.jianceShifouYouShipin() ? 2 : 0;
//     };
//     e.prototype.huoqu_shifou_changping_shouji = function () {
//         var e = cc.view.getVisibleSize();
//         return e.height / e.width > 2 || e.width / e.height > 2;
//     };
//     e.prototype.kaishi_luping = function (e) {
//         if (void 0 === e) {
//             e = {};
//         }
//         Log.d(this.logTag, "begin lupin");
//         var t = e.time || 30;
//         ailin_sdk_manager.kaishiLuping(t, function (t) {
//             1 === t
//                 ? e.success
//                     ? e.success()
//                     : AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "分享成功!"))
//                 : 2 === t
//                 ? e.fail
//                     ? e.fail(t)
//                     : AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "录屏时间太短!"))
//                 : 0 === t
//                 ? e.fail
//                     ? e.fail(t)
//                     : AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "分享视频失败!"))
//                 : 3 === t &&
//                   (e.fail
//                       ? e.fail(t)
//                       : AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "没有录制视频哦!")));
//         });
//         if (ailin_sdk_manager.instance) {
//             ailin_sdk_manager.instance.stopCanShare = !1;
//         }
//     };
//     e.prototype.tingzhi_luping = function (e) {
//         if (void 0 === e) {
//             e = !1;
//         }
//         Log.d(this.logTag, "stop lupin");
//         ailin_sdk_manager.tingzhiLuping(e);
//     };
//     e.prototype.zanting_luping = function () {
//         ailin_sdk_manager.zantingLuping();
//     };
//     e.prototype.huifu_luping = function () {
//         ailin_sdk_manager.resumeLuPing();
//     };
//     e.prototype.shareVideo = function (e) {
//         var t = this;
//         if (e.eventCode) {
//             ailin_sdk_manager.gameEvent("share_video_" + e.eventCode);
//         }
//         ailin_sdk_manager.fenxiangShipin(function (o) {
//             Log.d(t.logTag, "shareVdType:", o);
//             1 === o
//                 ? (e.eventCode && ailin_sdk_manager.gameEvent("share_video_success_" + e.eventCode),
//                   e.success && e.success())
//                 : 2 === o
//                 ? (AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "录屏时间太短!")), e.fail && e.fail(o))
//                 : 0 === o
//                 ? (AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "分享视频失败!")), e.fail && e.fail(o))
//                 : 3 === o
//                 ? (AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "没有录制视频哦!")), e.fail && e.fail(o))
//                 : 4 === o && e.close && e.close();
//         });
//     };
//     e.xianshiFenxiangShipinDuihuakuang = function (e) {
//         if (void 0 === e) {
//             e = {};
//         }
//         ailin_sdk_manager.xianshiFenxiangShipinDuihuakuang(function (t) {
//             1 === t
//                 ? e.success
//                     ? e.success()
//                     : AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "分享成功!"))
//                 : 2 === t
//                 ? e.fail
//                     ? e.fail(t)
//                     : AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "录屏时间太短!"))
//                 : 0 === t
//                 ? e.fail
//                     ? e.fail(t)
//                     : AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "分享视频失败!"))
//                 : 3 === t &&
//                   (e.fail
//                       ? e.fail(t)
//                       : AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "没有录制视频哦!")));
//         });
//     };
//     e._instance = null;
//     return e;
// })();
// exports.default = n;


const $macros = require("./AL_Framework_Macros");

/**
 * SDK Helper 类
 */
class AL_Framework_SDK_Helper {
  constructor() {
    this.logTag = "[AL_Framework_SDK_Helper]";
    this.videoState = false;
  }

  /**
   * 获取 AL_Framework_SDK_Helper 的单例实例
   * @returns {AL_Framework_SDK_Helper} AL_Framework_SDK_Helper 的实例
   */
  static Instance() {
    if (!this._instance) {
      this._instance = new AL_Framework_SDK_Helper();
    }
    return this._instance;
  }

  /**
   * 触发震动
   * @param {boolean} isLongVibrate 是否长震动
   */
  vibrate(isLongVibrate = false) {
    if (Manager.settingStorage.zhendong_zhuangtai) {
      isLongVibrate ? ailin_sdk_manager.vibrateLong() : ailin_sdk_manager.vibrateShort();
    }
  }

  /**
   * 分享或视频的回调处理
   * @param {Object} [callbackObj] 回调对象
   */
  handle_fenxiang_huo_shipin_huidiao(callbackObj = {}) {
    const shareOrVideo = this.huoquFenxiangHuoShipinZhuangtai();
    if (shareOrVideo === 0) {
      callbackObj.notExistCall
        ? callbackObj.notExistCall()
        : Manager.tips.show(Manager.languageManager.huoqu_biaoqian_neirong("framework", "暂无视频"));
    } else if (shareOrVideo === 2) {
      this.videoState = true;
      window.vivoPlayVDCallBack = () => {
        setTimeout(() => {
          Manager.eventCenter.emit($macros.Macro.CHANGE_MUSIC_EVENT, true);
          this.videoState = false;
        }, 100);
      };
      ailin_sdk_manager.xianshiJiliShipinGuanggao((result) => {
        if (result) {
          callbackObj.success && callbackObj.success();
        } else {
          callbackObj.fail
            ? callbackObj.fail()
            : Manager.tips.show(Manager.languageManager.huoqu_biaoqian_neirong("framework", "视频播放失败"));
        }
      });
    }
  }

  /**
   * 获取分享或视频的状态
   * @returns {number} 返回分享或视频的状态
   */
  huoquFenxiangHuoShipinZhuangtai() {
    return ailin_sdk_manager.jianceShifouYouShipin() ? 2 : 0;
  }

  /**
   * 判断是否为长屏手机
   * @returns {boolean} 是否为长屏手机
   */
  huoqu_shifou_changping_shouji() {
    const visibleSize = cc.view.getVisibleSize();
    return visibleSize.height / visibleSize.width > 2 || visibleSize.width / visibleSize.height > 2;
  }

  /**
   * 开始录屏
   * @param {Object} [options] 录屏选项
   */
  kaishi_luping(options = {}) {
    Log.d(this.logTag, "begin lupin");
    const recordingTime = options.time || 30;
    ailin_sdk_manager.kaishiLuping(recordingTime, (status) => {
      if (status === 1) {
        options.success
          ? options.success()
          : AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "分享成功!"));
      } else if (status === 2) {
        options.fail
          ? options.fail(status)
          : AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "录屏时间太短!"));
      } else if (status === 0) {
        options.fail
          ? options.fail(status)
          : AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "分享视频失败!"));
      } else if (status === 3) {
        options.fail
          ? options.fail(status)
          : AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "没有录制视频哦!"));
      }
    });
    if (ailin_sdk_manager.instance) {
      ailin_sdk_manager.instance.stopCanShare = false;
    }
  }

  /**
   * 停止录屏
   * @param {boolean} [isShare] 是否分享
   */
  tingzhi_luping(isShare = false) {
    Log.d(this.logTag, "stop lupin");
    ailin_sdk_manager.tingzhiLuping(isShare);
  }

  /**
   * 暂停录屏
   */
  zanting_luping() {
    ailin_sdk_manager.zantingLuping();
  }

  /**
   * 恢复录屏
   */
  huifu_luping() {
    ailin_sdk_manager.resumeLuPing();
  }

  /**
   * 分享视频
   * @param {Object} options 分享选项
   */
  shareVideo(options) {
    if (options.eventCode) {
      ailin_sdk_manager.gameEvent("share_video_" + options.eventCode);
    }
    ailin_sdk_manager.fenxiangShipin((status) => {
      Log.d(this.logTag, "shareVdType:", status);
      if (status === 1) {
        options.eventCode && ailin_sdk_manager.gameEvent("share_video_success_" + options.eventCode);
        options.success && options.success();
      } else if (status === 2) {
        AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "录屏时间太短!"));
        options.fail && options.fail(status);
      } else if (status === 0) {
        AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "分享视频失败!"));
        options.fail && options.fail(status);
      } else if (status === 3) {
        AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "没有录制视频哦!"));
        options.fail && options.fail(status);
      } else if (status === 4) {
        options.close && options.close();
      }
    });
  }

  /**
   * 显示分享视频对话框
   * @param {Object} [callbackObj] 回调对象
   */
  static xianshiFenxiangShipinDuihuakuang(callbackObj = {}) {
    ailin_sdk_manager.xianshiFenxiangShipinDuihuakuang((status) => {
      if (status === 1) {
        callbackObj.success
          ? callbackObj.success()
          : AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "分享成功!"));
      } else if (status === 2) {
        callbackObj.fail
          ? callbackObj.fail(status)
          : AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "录屏时间太短!"));
      } else if (status === 0) {
        callbackObj.fail
          ? callbackObj.fail(status)
          : AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "分享视频失败!"));
      } else if (status === 3) {
        callbackObj.fail
          ? callbackObj.fail(status)
          : AL_APP_SDK_MANAGER.tips.show(AL_APP_SDK_MANAGER.languageManager.huoqu_biaoqian_neirong("framework", "没有录制视频哦!"));
      }
    });
  }
}

AL_Framework_SDK_Helper._instance = null;
exports.default = AL_Framework_SDK_Helper;
